package com.cnap.multiclouldmgmt.controller;

import com.cnap.multiclouldmgmt.model.CommonResult;
import com.cnap.multiclouldmgmt.model.RepByPage;
import com.cnap.multiclouldmgmt.model.k8sModels.*;
import com.cnap.multiclouldmgmt.model.log.OperationTypeEnum;
import com.cnap.multiclouldmgmt.model.privatecloud.CloudVendorInfo;
import com.cnap.multiclouldmgmt.service.CacheService;
import com.cnap.multiclouldmgmt.service.K8sClusterService;
import com.cnap.multiclouldmgmt.service.MultiCloudMgmtService;
import com.cnap.multiclouldmgmt.service.OperationLogService;
import com.cnap.multiclouldmgmt.util.CnapCloudMgmtConstants;
import com.cnap.multiclouldmgmt.util.TokenUtils;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.apache.commons.lang3.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.ArrayList;
import java.util.List;

/**
 * 集群控制台的各个接口，需要获取用户token才能访问
 * @author dyq
 */
@Api(tags ="混合云网管理-集群控制台对外api")
@RequestMapping(path = "/cnap/multicloudmgmtApi/v1/k8sCluster")
@RestController
@ResponseBody
public class K8sClusterApiController {

    private final static Logger LOGGER = LoggerFactory.getLogger(K8sClusterApiController.class);

    @Autowired
    private K8sClusterService k8sClusterService;

    @Autowired
    private OperationLogService operationLogService;

    @Autowired
    private CacheService cacheService;

    @Autowired
    private MultiCloudMgmtService multiCloudMgmtService;

    /**
     * 根据条件获取node节点列表
     * @param cloudVendor  入参云供应商cloudVendor
     * @param k8sClusterName 集群的名称
     * @param keyword 搜索关键字
     * @param pageSize 分页大小
     * @param pageNo 页数
     * @return
     */
    @ApiOperation(value = "10-1 根据条件获取node节点列表",httpMethod = "GET", notes = "入参云供应商cloudVendor，" +
            "选择集群的名称k8sClusterName,搜索关键字keyword")
    @RequestMapping(path = "/getK8sClusterNodeInfos",method = RequestMethod.GET)
    public CommonResult<RepByPage<NodeModel>> getK8sClusterNodeInfos(String cloudVendor, String k8sClusterName, String keyword,
                                                                     int pageSize, int pageNo) {


        try {


            if (StringUtils.isEmpty(cloudVendor)||StringUtils.isEmpty(k8sClusterName)) {

                String createUser = CnapCloudMgmtConstants.ADMIN_USER_NAME;

                //缓存获取
                List<RepByPage<NodeModel>> nodeInfos = cacheService.getK8sNodeInfo(createUser);

                //按条件组装
                RepByPage<NodeModel> result = new RepByPage<>();
                result.setPageNo(pageNo);
                result.setPageSize(pageSize);
                result.setTotalNum(0);
                result.setResult(new ArrayList<>());

                if ((nodeInfos == null)||(nodeInfos.isEmpty())){
                    return CommonResult.success(result);
                }

                //获取不同集群的node
                for (RepByPage<NodeModel> nodeModelRepByPage:nodeInfos){

                    List<NodeModel> nodeModels = new ArrayList<>();

                    for (NodeModel nodeModel:nodeModelRepByPage.getResult()){

                        //查看是否有筛选条件
                        boolean addFlag = true;

                        if (StringUtils.isNotEmpty(cloudVendor)){
                            if (!StringUtils.equals(nodeModel.getCloudVendor(),cloudVendor)){
                                addFlag = false;
                            }
                        }

                        if (StringUtils.isNotEmpty(k8sClusterName)){
                            if (!StringUtils.equals(nodeModel.getK8sClusterName(),k8sClusterName)){
                                addFlag = false;
                            }
                        }

                        if (StringUtils.isNotEmpty(keyword)){
                            if (!StringUtils.containsIgnoreCase(nodeModel.getNodeName(),keyword)){
                                addFlag = false;
                            }
                        }

                        if (addFlag){
                            nodeModels.add(nodeModel);
                        }
                    }

                    //统计总数
                    result.setTotalNum(result.getTotalNum() + nodeModels.size());
                    result.getResult().addAll(nodeModels);
                }

                //做分页
                int beginIndex = 0;
                int endIndex = result.getResult().size();
                if (((pageNo - 1)*pageSize) > endIndex){
                    result.setResult(new ArrayList<>());

                }else {
                    beginIndex = (pageNo - 1) * pageSize;
                    endIndex = Math.min((pageNo * pageSize), endIndex);
                    result.setResult(result.getResult().subList(beginIndex, endIndex));
                }
                return CommonResult.success(result);

            }
            //根据条件获取节点数据
            return CommonResult.success(k8sClusterService.getK8sClusterNodeInfosByConditions(
                                cloudVendor,k8sClusterName, keyword,pageSize,pageNo));

        }catch (Exception e){

            LOGGER.error("API K8sClusterController getK8sClusterNodeInfos error pageNo={}",pageNo,e);

            return CommonResult.failed(e.getMessage());
        }
    }

    /**
     * 根据条件获取namespace列表
     * @param cloudVendor
     * @param k8sClusterName
     * @param keyword
     * @param pageSize
     * @param pageNo
     * @return
     */
    @ApiOperation(value = "10-4 根据条件获取namespace列表",httpMethod = "GET", notes = "入参云供应商cloudVendor，选择集群的名称k8sClusterName,搜索关键字keyword")
    @RequestMapping(path = "/getK8sClusterNameSpaces",method = RequestMethod.GET)
    public CommonResult<RepByPage<NameSpaceModel>> getK8sClusterNameSpaces(String cloudVendor, String k8sClusterName, String keyword,
                                                                           int pageSize, int pageNo,String accountName) {
        try {
            //如果不传参数的话
            if (StringUtils.isEmpty(cloudVendor)||StringUtils.isEmpty(k8sClusterName)) {

                String createUser = CnapCloudMgmtConstants.ADMIN_USER_NAME;

                //缓存获取
                List<RepByPage<NameSpaceModel>> nsInfos = cacheService.getK8sNsInfo(createUser);

                //按条件组装
                RepByPage<NameSpaceModel> result = new RepByPage<>();
                result.setPageNo(pageNo);
                result.setPageSize(pageSize);
                result.setTotalNum(0);
                result.setResult(new ArrayList<>());

                if ((nsInfos == null)||(nsInfos.isEmpty())){
                    return CommonResult.success(result);
                }

                //获取不同集群的node
                for (RepByPage<NameSpaceModel> nameSpaceModelRepByPage:nsInfos){

                    List<NameSpaceModel> nameSpaceModels = new ArrayList<>();

                    for (NameSpaceModel nameSpaceModel:nameSpaceModelRepByPage.getResult()){

                        //查看是否有筛选条件
                        boolean addFlag = true;

                        if (StringUtils.isNotEmpty(cloudVendor)){
                            if (!StringUtils.equals(nameSpaceModel.getCloudVendor(),cloudVendor)){
                                addFlag = false;
                            }
                        }

                        if (StringUtils.isNotEmpty(k8sClusterName)){
                            if (!StringUtils.equals(nameSpaceModel.getK8sClusterName(),k8sClusterName)){
                                addFlag = false;
                            }
                        }

                        if (StringUtils.isNotEmpty(keyword)){
                            if (!StringUtils.containsIgnoreCase(nameSpaceModel.getNameSpaceName(),keyword)){
                                addFlag = false;
                            }
                        }

                        if (addFlag){
                            nameSpaceModels.add(nameSpaceModel);
                        }
                    }

                    //统计总数
                    result.setTotalNum(result.getTotalNum() + nameSpaceModels.size());
                    result.getResult().addAll(nameSpaceModels);
                }

                //做分页
                int beginIndex = 0;
                int endIndex = result.getResult().size();
                if (((pageNo - 1)*pageSize) > endIndex){
                    result.setResult(new ArrayList<>());

                }else {
                    beginIndex = (pageNo - 1) * pageSize;
                    endIndex = Math.min((pageNo * pageSize), endIndex);
                    result.setResult(result.getResult().subList(beginIndex, endIndex));
                }
                return CommonResult.success(result);

            }

            //获取命名空间
            return CommonResult.success(k8sClusterService.getK8sClusterNameSpaces(cloudVendor,
                            k8sClusterName,keyword, pageSize,pageNo,accountName));

        }catch (Exception e){

            LOGGER.error("K8sClusterController getK8sClusterNameSpaces error k8sClusterName={}",k8sClusterName,e);

            return CommonResult.failed(e.getMessage());
        }
    }

    /**
     * 创建namespace
     * @param nameSpaceModel
     * @return
     */
    @ApiOperation(value = "10-5 创建namespace",httpMethod = "POST", notes = "入参云供应商名称，集群名称，命名空间名称，描述")
    @RequestMapping(path = "/addK8sClusterNameSpaces",method = RequestMethod.POST)
    public CommonResult<Void> addK8sClusterNameSpaces(@RequestBody NameSpaceModel nameSpaceModel) {

        try {

            //创建namespace
            k8sClusterService.addK8sClusterNameSpaces(nameSpaceModel);

            //统一记录操作日志
            operationLogService.saveOperationLog(OperationTypeEnum.ADD.getType(), "增加namespace：" + nameSpaceModel.getNameSpaceName());

            return CommonResult.successMsg("addK8sClusterNameSpaces success");

        }catch (Exception e){

            LOGGER.error("K8sClusterController getK8sClusterNameSpaces error nameSpaceModel.getNameSpaceName={}",
                    nameSpaceModel.getNameSpaceName(),e);

            return CommonResult.failed(e.getMessage());
        }
    }
    
    /**
     * 根据条件获取工作负载列表
     * @param cloudVendor
     * @param k8sClusterName
     * @param keyword
     * @param svcName
     * @param pageSize
     * @param pageNo
     * @return
     */
    @ApiOperation(value = "10-7 根据条件获取工作负载列表",httpMethod = "GET", notes = "入参云供应商cloudVendor，选择集群的名称k8sClusterName,搜索关键字keyword,服务名称svcName")
    @RequestMapping(path = "/getK8sClusterWorkLoads",method = RequestMethod.GET)
    public CommonResult<RepByPage<WorkLoadModel>> getK8sClusterWorkLoads(String cloudVendor, String k8sClusterName, String keyword,
                                                                         String svcName, int pageSize, int pageNo) {
        try {

            //如果不传参数的话
            if (StringUtils.isEmpty(cloudVendor)||StringUtils.isEmpty(k8sClusterName)) {

                String createUser = CnapCloudMgmtConstants.ADMIN_USER_NAME;

                //缓存获取
                List<RepByPage<WorkLoadModel>> workLoadInfos = cacheService.getK8sWorkLoadInfo(createUser);

                //按条件组装
                RepByPage<WorkLoadModel> result = new RepByPage<>();
                result.setPageNo(pageNo);
                result.setPageSize(pageSize);
                result.setTotalNum(0);
                result.setResult(new ArrayList<>());

                if ((workLoadInfos == null)||(workLoadInfos.isEmpty())){
                    return CommonResult.success(result);
                }

                //获取不同集群的node
                for (RepByPage<WorkLoadModel> workLoadModelRepByPage:workLoadInfos){

                    List<WorkLoadModel> workLoadModels = new ArrayList<>();

                    for (WorkLoadModel workLoadModel:workLoadModelRepByPage.getResult()){

                        //查看是否有筛选条件
                        boolean addFlag = true;

                        if (StringUtils.isNotEmpty(cloudVendor)){
                            if (!StringUtils.equals(workLoadModel.getCloudVendor(),cloudVendor)){
                                addFlag = false;
                            }
                        }

                        if (StringUtils.isNotEmpty(k8sClusterName)){
                            if (!StringUtils.equals(workLoadModel.getK8sClusterName(),k8sClusterName)){
                                addFlag = false;
                            }
                        }

                        if (StringUtils.isNotEmpty(keyword)){
                            if (!StringUtils.containsIgnoreCase(workLoadModel.getWorkLoadName(),keyword)){
                                addFlag = false;
                            }
                        }

                        if (StringUtils.isNotEmpty(svcName)){
                            if (!StringUtils.containsIgnoreCase(workLoadModel.getSvcName(),svcName)){
                                addFlag = false;
                            }
                        }

                        if (addFlag){
                            workLoadModels.add(workLoadModel);
                        }
                    }

                    //统计总数
                    result.setTotalNum(result.getTotalNum() + workLoadModels.size());
                    result.getResult().addAll(workLoadModels);
                }

                //做分页
                int beginIndex = 0;
                int endIndex = result.getResult().size();
                if (((pageNo - 1)*pageSize) > endIndex){
                    result.setResult(new ArrayList<>());

                }else {
                    beginIndex = (pageNo - 1) * pageSize;
                    endIndex = Math.min((pageNo * pageSize), endIndex);
                    result.setResult(result.getResult().subList(beginIndex, endIndex));
                }
                return CommonResult.success(result);

            }

            //根据条件获取工作负载列表
            return CommonResult.success(k8sClusterService.getK8sClusterWorkLoads(cloudVendor,k8sClusterName,
                                        keyword,svcName,pageSize,pageNo));

        }catch (Exception e){

            LOGGER.error("Api K8sClusterController getK8sClusterWorkLoads error k8sClusterName={}", k8sClusterName,e);

            return CommonResult.failed(e.getMessage());
        }
    }

    /**
     * 创建工作负载
     * @param workLoadModel
     * @return
     */
    @ApiOperation(value = "2-8 创建工作负载",httpMethod = "POST", notes = "入参云供应商cloudVendor，集群的名称k8sClusterName,部署的yaml内容")
    @RequestMapping(path = "/addK8sClusterWorkLoad",method = RequestMethod.POST)
    public CommonResult<Void> addK8sClusterWorkLoad(@RequestBody WorkLoadModel workLoadModel) {

        try {

            //服务商不能为空
            if (StringUtils.isEmpty(workLoadModel.getCloudVendor())){
                throw new Exception("请选择集群服务商和集群名称");
            }

            //集群名称不能为空
            if (StringUtils.isEmpty(workLoadModel.getK8sClusterName())){
                throw  new Exception("请选择集群名称");
            }

            //创建工作负载
            k8sClusterService.addK8sClusterWorkLoad(workLoadModel.getCloudVendor(),workLoadModel.getK8sClusterName(), workLoadModel.getYaml());

            //统一记录操作日志
            operationLogService.saveOperationLog(OperationTypeEnum.ADD.getType(), "创建工作负载");

            return CommonResult.successMsg("addK8sClusterWorkLoads success");

        }catch (Exception e){

            LOGGER.error("K8sClusterController addK8sClusterWorkLoad error k8sClusterName={}",
                    workLoadModel.getK8sClusterName(),e);

            return CommonResult.failed(e.getMessage());
        }

    }

    /**
     * 根据条件获取容器组
     * @param cloudVendor
     * @param k8sClusterName
     * @param keyword
     * @param namespace
     * @param svcName
     * @param workLoadName
     * @param pageSize
     * @param pageNo
     * @return
     */
    @ApiOperation(value = "2-12 根据条件获取容器组",httpMethod = "GET", notes = "入参云供应商cloudVendor，选择集群的名称k8sClusterName,搜索关键字keyword," +
            "namespace,命名空间名称，svcName--服务名称，workLoadName-负载名称")
    @RequestMapping(path = "/getK8sClusterPods",method = RequestMethod.GET)
    public CommonResult<RepByPage<PodModel>> getK8sClusterPods(String cloudVendor, String k8sClusterName, String keyword,
                                                               String namespace, String svcName, String workLoadName,
                                                               int pageSize, int pageNo) {

        try {

            LOGGER.info("K8sClusterController getK8sClusterPods k8sClusterName={}",
                    k8sClusterName);

            //如果不传参数的话
            if (StringUtils.isEmpty(cloudVendor)||StringUtils.isEmpty(k8sClusterName)) {

                String createUser = CnapCloudMgmtConstants.ADMIN_USER_NAME;

                //缓存获取
                List<RepByPage<PodModel>> podInfos = cacheService.getK8sPodInfo(createUser);

                //按条件组装
                RepByPage<PodModel> result = new RepByPage<>();
                result.setPageNo(pageNo);
                result.setPageSize(pageSize);
                result.setTotalNum(0);
                result.setResult(new ArrayList<>());

                if ((podInfos == null)||(podInfos.isEmpty())){
                    return CommonResult.success(result);
                }

                //获取不同集群的node
                for (RepByPage<PodModel> podModelRepByPage:podInfos){

                    List<PodModel> podModels = new ArrayList<>();

                    for (PodModel podModel:podModelRepByPage.getResult()){

                        //查看是否有筛选条件
                        boolean addFlag = true;

                        if (StringUtils.isNotEmpty(cloudVendor)){
                            if (!StringUtils.equals(podModel.getCloudVendor(),cloudVendor)){
                                addFlag = false;
                            }
                        }

                        if (StringUtils.isNotEmpty(k8sClusterName)){
                            if (!StringUtils.equals(podModel.getK8sClusterName(),k8sClusterName)){
                                addFlag = false;
                            }
                        }

                        if (StringUtils.isNotEmpty(keyword)){
                            if (!StringUtils.containsIgnoreCase(podModel.getPodName(),keyword)){
                                addFlag = false;
                            }
                        }

                        if (StringUtils.isNotEmpty(namespace)){
                            if (!StringUtils.containsIgnoreCase(podModel.getNamespace(),namespace)){
                                addFlag = false;
                            }
                        }

                        if (StringUtils.isNotEmpty(workLoadName)){
                            if (podModel.getWorkLoadModel() != null) {
                                if (!StringUtils.containsIgnoreCase(podModel.getWorkLoadModel().getWorkLoadName(), workLoadName)) {
                                    addFlag = false;
                                }
                            }
                        }

                        if (StringUtils.isNotEmpty(svcName)){
                            if (podModel.getWorkLoadModel() != null) {
                                if (!StringUtils.containsIgnoreCase(podModel.getWorkLoadModel().getSvcName(), svcName)) {
                                    addFlag = false;
                                }
                            }
                        }

                        if (addFlag){
                            podModels.add(podModel);
                        }
                    }

                    //统计总数
                    result.setTotalNum(result.getTotalNum() + podModels.size());
                    result.getResult().addAll(podModels);
                }

                //做分页
                int beginIndex = 0;
                int endIndex = result.getResult().size();
                if (((pageNo - 1)*pageSize) > endIndex){
                    result.setResult(new ArrayList<>());

                }else {
                    beginIndex = (pageNo - 1) * pageSize;
                    endIndex = Math.min((pageNo * pageSize), endIndex);
                    result.setResult(result.getResult().subList(beginIndex, endIndex));
                }
                return CommonResult.success(result);

            }

            //根据条件获取容器组
            return CommonResult.success(k8sClusterService.getK8sClusterPods(cloudVendor,k8sClusterName,keyword,namespace,
                    svcName,workLoadName,pageSize,pageNo));

        }catch (Exception e){

            LOGGER.error("K8sClusterController getK8sClusterPods error k8sClusterName={}",
                    k8sClusterName,e);

            return CommonResult.failed(e.getMessage());
        }

    }


    /**
     * 根据条件获取具体容器
     * @param cloudVendor
     * @param k8sClusterName
     * @param namespace
     * @param podName
     * @return
     */
    @ApiOperation(value = "10-14 根据条件获取具体容器",httpMethod = "GET", notes = "入参云供应商cloudVendor，选择集群的名称k8sClusterName," +
                    "namespace，pod名称")
    @RequestMapping(path = "/getK8sClusterPodContainers",method = RequestMethod.GET)
    public CommonResult<List<ContainerModel>> getK8sClusterPodContainers(String cloudVendor, String k8sClusterName,
                                                                         String namespace, String podName) {

        try {

            //根据条件获取具体容器
            return CommonResult.success(k8sClusterService.getK8sClusterPodContainers(cloudVendor,k8sClusterName,namespace,podName));

        }catch (Exception e){

            LOGGER.error("K8sClusterController getK8sClusterPodContainers error podName={}", podName,e);

            return CommonResult.failed(e.getMessage());
        }
    }

    /**
     * 根据条件获取服务们
     * @param cloudVendor
     * @param k8sClusterName
     * @param keyword
     * @param pageSize
     * @param pageNo
     * @return
     */
    @ApiOperation(value = "10-14 根据条件获取服务们",httpMethod = "GET", notes = "入参云供应商cloudVendor，选择集群的名称k8sClusterName,搜索关键字keyword,")
    @RequestMapping(path = "/getK8sClusterSvcs",method = RequestMethod.GET)
    public CommonResult<RepByPage<SvcModel>> getK8sClusterSvcs(String cloudVendor, String k8sClusterName, String keyword,
                                                               int pageSize, int pageNo) {

        try {

            //如果不传参数的话
            if (StringUtils.isEmpty(cloudVendor)||StringUtils.isEmpty(k8sClusterName)) {

                String createUser = CnapCloudMgmtConstants.ADMIN_USER_NAME;

                //缓存获取
                List<RepByPage<SvcModel>> svcInfos = cacheService.getK8sSvcInfo(createUser);

                //按条件组装
                RepByPage<SvcModel> result = new RepByPage<>();
                result.setPageNo(pageNo);
                result.setPageSize(pageSize);
                result.setTotalNum(0);
                result.setResult(new ArrayList<>());

                if ((svcInfos == null) || (svcInfos.isEmpty())) {
                    return CommonResult.success(result);
                }

                //获取不同集群的node
                for (RepByPage<SvcModel> svcModelRepByPage : svcInfos) {

                    List<SvcModel> svcModels = new ArrayList<>();

                    for (SvcModel svcModel : svcModelRepByPage.getResult()) {

                        //查看是否有筛选条件
                        boolean addFlag = true;

                        if (StringUtils.isNotEmpty(cloudVendor)) {
                            if (!StringUtils.equals(svcModel.getCloudVendor(), cloudVendor)) {
                                addFlag = false;
                            }
                        }

                        if (StringUtils.isNotEmpty(k8sClusterName)) {
                            if (!StringUtils.equals(svcModel.getK8sClusterName(), k8sClusterName)) {
                                addFlag = false;
                            }
                        }

                        if (StringUtils.isNotEmpty(keyword)) {
                            if (!StringUtils.containsIgnoreCase(svcModel.getSvcName(), keyword)) {
                                addFlag = false;
                            }
                        }

                        if (addFlag) {
                            svcModels.add(svcModel);
                        }
                    }

                    //统计总数
                    result.setTotalNum(result.getTotalNum() + svcModels.size());
                    result.getResult().addAll(svcModels);
                }

                //做分页
                int beginIndex = 0;
                int endIndex = result.getResult().size();
                if (((pageNo - 1)*pageSize) > endIndex){
                    result.setResult(new ArrayList<>());

                }else {
                    beginIndex = (pageNo - 1) * pageSize;
                    endIndex = Math.min((pageNo * pageSize), endIndex);
                    result.setResult(result.getResult().subList(beginIndex, endIndex));
                }
                return CommonResult.success(result);
            }

            //根据条件获取服务们
            return CommonResult.success(k8sClusterService.getK8sClusterSvcs(cloudVendor,k8sClusterName,keyword,pageSize,pageNo));

        }catch (Exception e){

            LOGGER.error("Api K8sClusterController getK8sClusterSvcs error k8sClusterName={}", k8sClusterName,e);

            return CommonResult.failed(e.getMessage());
        }
    }


    /**
     * 部署一个服务
     * @param svcModel
     * @return
     */
    @ApiOperation(value = "10-15 部署一个服务",httpMethod = "POST", notes = "入参云供应商cloudVendor，选择集群的名称k8sClusterName,namespace，yaml,")
    @RequestMapping(path = "/addK8sClusterSvc",method = RequestMethod.POST)
    public CommonResult<Void> addK8sClusterSvc(@RequestBody SvcModel svcModel) {

        try {
            //服务商不能为空
            if (StringUtils.isEmpty(svcModel.getCloudVendor())){
                throw new Exception("请选择集群服务商和集群名称");
            }

            //集群名称不能为空
            if (StringUtils.isEmpty(svcModel.getK8sClusterName())){
                throw  new Exception("请选择集群名称");
            }

            //部署一个服务
            k8sClusterService.addK8sClusterSvc(svcModel.getCloudVendor(),svcModel.getK8sClusterName(),svcModel.getYaml());

            //统一记录操作日志
            operationLogService.saveOperationLog(OperationTypeEnum.ADD.getType(), "部署一个服务");

            return CommonResult.successMsg("addK8sClusterSvc success");

        }catch (Exception e){

            LOGGER.error("K8sClusterController addK8sClusterSvc error k8sClusterName={}", svcModel.getK8sClusterName(),e);

            return CommonResult.failed(e.getMessage());
        }

    }
    /**
     * 获取集群还有几个master节点数量
     * @param cloudVendor
     * @param k8sClusterName
     * @return
     */
    @ApiOperation(value = "10-18 获取集群还有几个master节点数量",httpMethod = "GET", notes = "入参云供应商cloudVendor，选择集群的名称k8sClusterName")
    @RequestMapping(path = "/getK8sClusterMasterNodeNum",method = RequestMethod.GET)
    public CommonResult<Integer> getK8sClusterMasterNodeNum(String cloudVendor, String k8sClusterName) {

        try {
            if (StringUtils.isEmpty(cloudVendor)||StringUtils.isEmpty(k8sClusterName)){
                throw new Exception("参数不全");
            }

            //获取集群还有几个master节点数量
            return CommonResult.success(k8sClusterService.getK8sClusterMasterNodeNum(cloudVendor,k8sClusterName));
        }catch (Exception e){

            LOGGER.error("K8sClusterController getK8sClusterMasterNodeNum error k8sClusterName={}", k8sClusterName,e);

            return CommonResult.failed(e.getMessage());
        }
    }


    @ApiOperation(value = "10-19 获取所有的云的基础信息",httpMethod = "GET", notes = "")
    @RequestMapping(path = "/getAllCloudVendorInfo",method = RequestMethod.GET)
    public CommonResult<List<CloudVendorInfo>> getAllCloudVendorInfo() {


        String userName = TokenUtils.getUserName();

        List<CloudVendorInfo> cloudVendorInfos =  multiCloudMgmtService.getAllCloudVenderAccountInfo(userName);

        return CommonResult.success(cloudVendorInfos);

    }
}
